package com.example.javatwo.service.cg.dwh;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;

import com.example.javatwo.mapper.cg.dwh.FukuanMapper;
import com.example.javatwo.pojo.cg.dwh.PrepaymentmainPojo;
import com.example.javatwo.pojo.cg.dwh.PrepaymentmaindetailPojo;
import com.example.javatwo.util.CreateNewId;

@Service
public class FukuanService{
	
	@Autowired
	private FukuanMapper fukuanMapper;
	

	/**
	 * 预付款主表
	 * @return
	 */
	public List<PrepaymentmainPojo> findPrepaymentmainPojo(int page){
		List<PrepaymentmainPojo> zhu = this.fukuanMapper.findPrepaymentmainPojo(page);
		for (PrepaymentmainPojo prepaymentmainPojo : zhu) {
			prepaymentmainPojo.setPrepaymentmaindetailPojos(this.fukuanMapper.findPrepaymentmaindetailPojo(prepaymentmainPojo.getFundbillid()));
		}
		return zhu;
	}
	
	/**
	 * 查询从表预收款
	 * @return
	 */
	public List<PrepaymentmaindetailPojo> findPrepaymentmaindetailPojo(String fundBillID){
		return this.fukuanMapper.findPrepaymentmaindetailPojo(fundBillID);
	}
	
	/**
	 * 添加主表和从表
	 * @param pojo
	 */
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED,readOnly=false)
	public void insertrepaymentmainPojo(PrepaymentmainPojo pojo){
		this.fukuanMapper.insertrepaymentmainPojo(pojo);
	}
	
	/**
	 * 删除--其实是修改状态
	 * @param fundBillID
	 */
	//@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED,readOnly=false)
	public void dwhDelete(String fundBillID){
		this.fukuanMapper.dwhDelete(fundBillID);
	}
	
	/**
	 * 删除主表从表  真正删除
	 * @param fundBillID  主表id
	 */
	public void dwhShanchuzhubiao(String fundBillID){
		this.fukuanMapper.dwhdeletecongbiao(fundBillID);
		this.fukuanMapper.dwhdeletezhubiao(fundBillID);
	}
	
	/**
	 * 总页数
	 * @return
	 */
	public int count(){
		return this.fukuanMapper.countZong();
	}
	
	/**
	 * 审核
	 * @param fundbillid
	 */
	public void dwhShenhe(String fundbillid){
		this.fukuanMapper.dwhShenhe(fundbillid);
	}
	
	/**
	 * 反审核
	 * @param fundbillid
	 */
	public void dwhfansShenhe(String fundbillid){
		this.fukuanMapper.dwhfansShenhe(fundbillid);
	}
	
	/**
	 * 最大单号
	 * @return
	 */
	public String dwhZuidaDanhao(String data){
		String data1 = data.replace("-", "");
		String datas = this.fukuanMapper.dwhZuidaDanhao(data1);
		return ZiDongdanhao.Danhaoshengcheng(datas);
	}
	
	/**
	 * 审核修改供应商主文件剩余额度和期末预付款
	 * @param money
	 * @param gongyingshangID
	 */
	public void dwhXiugaiGongyingshangJine(double money,String gongyingshangID){
		this.fukuanMapper.dwhXiugaiGongyingshangJine(money, gongyingshangID);
	}
	
	/**
	 * 审核修改供应商主文件剩余额度和期末预付款  反
	 * @param money
	 * @param gongyingshangID
	 */
	public void dwhXiugaiGongyingshangJineFan(double money,String gongyingshangID){
		this.fukuanMapper.dwhXiugaiGongyingshangJineFan(money, gongyingshangID);
	}
	
}
